home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5974 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  46 lines

  1. Path: newshost.cyberramp.net!news
  2. From: sinan@cyberramp.net (John Noland)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help With Pointers
  5. Date: 22 Feb 1996 05:42:18 GMT
  6. Organization: Prose Software
  7. Message-ID: <4ggvnq$2bt@newshost.cyberramp.net>
  8. References: <4g67cj$6cv@hobbes.compusult.nf.ca>
  9. NNTP-Posting-Host: ramp1-27.cyberramp.net
  10. X-Newsreader: WinVN 0.99.5
  11.  
  12. In article <4g67cj$6cv@hobbes.compusult.nf.ca>, bryan@public.compusult.nf.ca says...
  13. >
  14. >Hi
  15. >
  16. >Is there any way to assign a char pointer to a float pointer?
  17. >
  18. >I had to do some byte rotation on binary data.  I rotated 
  19. >the characters and know want to point a float at the first
  20. >character position to read back a 4 byte float.
  21. >
  22. >I'am actually trying to read SGI binary data with a PC.  I've been told
  23. >that the SGI bytes ( not bits ) are rotated versus a PC.  Any help 
  24. >would be appreciated. Are the bytes rotated?
  25. >
  26.  
  27. Have you tried this approach and failed? I suspect that you haven't tried
  28. it. You can have a pointer of type char and a pointer of type float pointing
  29. to the same place. I might get chastised by the gurus for this, but you 
  30. know what? I don't care. You might try just a simple union as your destination
  31. variable. So, you might wind up with something like this;
  32.  
  33. char    SGI_source[4];
  34. union {
  35.     char    d1[4];
  36.     float    d2;
  37. } dest;
  38.  
  39. dest.d1[1] = SGI_source[2];
  40. dest.d2[2] = SGI_source[1];
  41.  
  42. or however the byte rotation needs to be done.
  43.  
  44. -John 
  45.  
  46.